import java.util.Scanner;
public class Maxsub {
    public static int maxsub(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int max_so_far = nums[0], max_ending_here = nums[0];
        for (int i = 1; i < nums.length; i++) {
            max_ending_here = Math.max(max_ending_here + nums[i], nums[i]);
            max_so_far = Math.max(max_so_far, max_ending_here);
        }
        return max_so_far;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = scanner.nextInt(); // 读取数组的大小
        int[] array = new int[size]; // 创建一个指定大小的数组
        for (int i = 0; i < size; i++) {
            array[i] = scanner.nextInt(); // 读取每个整数并存储到数组中
        }
        System.out.println(maxsub(array));
    }
}
